package top.sjydzq.www.controller.Mall;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import top.sjydzq.www.bean.Notice;
import top.sjydzq.www.bean.Product;
import top.sjydzq.www.service.NoticeService;
import top.sjydzq.www.service.ProductService;

import java.util.List;

@Controller
public class IndexController {
    @Autowired
    private ProductService productService;
    @Autowired
    private NoticeService noticeService;

    @RequestMapping("/")
    public String index(Model model) {
        List<Product> bestSellers = productService.limitedSelectBestSellers(10);
        List<Product> mostStared = productService.limitedSelectMostStared(10);
        List<Product> newestProducts = productService.limitedSelect(15);
        // limitedSelect 默认根据id找最新V
        List<Notice> notices = noticeService.selectAll();
        // selectAll 默认按日期排序

        model.addAttribute("bestSellers", bestSellers);
        model.addAttribute("mostStared", mostStared);
        model.addAttribute("newestProducts", newestProducts);
        model.addAttribute("notices", notices);

        return "Mall/index";
    }
}
